package com.cc.blog.admin.controller;

import com.cc.blog.admin.domain.dto.AddCategoryReqDTO;
import com.cc.blog.admin.domain.dto.DeleteCategoryReqDTO;
import com.cc.blog.admin.domain.dto.FindCategoryPageListReqDTO;
import com.cc.blog.admin.service.AdminCategoryService;
import com.cc.blog.common.annotation.ApiOperationLog;
import com.cc.blog.common.utils.PageResult;
import com.cc.blog.common.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author cc
 * @Date 2024/7/10 14:11
 */
@RestController
@RequestMapping("/admin")
@Api(tags = "Admin 分类模块")
@AllArgsConstructor
public class AdminCategoryController {

    private final AdminCategoryService categoryService;

    @PostMapping("/category/add")
    @ApiOperation(value = "添加分类")
    @ApiOperationLog(description = "添加分类")
    public Result addCategory(@RequestBody @Validated AddCategoryReqDTO addCategoryReqDTO) {
        return categoryService.addCategory(addCategoryReqDTO);
    }

    @PostMapping("/category/list")
    @ApiOperation(value = "分类分页数据获取")
    @ApiOperationLog(description = "分类分页数据获取")
    public PageResult findCategoryList(@RequestBody @Validated FindCategoryPageListReqDTO findCategoryPageListReqDTO) {
        return categoryService.findCategoryList(findCategoryPageListReqDTO);
    }

    @PostMapping("/category/delete")
    @ApiOperation(value = "删除分类")
    @ApiOperationLog(description = "删除分类")
    public Result deleteCategory(@RequestBody @Validated DeleteCategoryReqDTO deleteCategoryReqDTO) {
        return categoryService.deleteCategory(deleteCategoryReqDTO);
    }

    @PostMapping("/category/select/list")
    @ApiOperation(value = "分类 Select 下拉列表数据获取")
    @ApiOperationLog(description = "分类 Select 下拉列表数据获取")
    public Result findCategorySelectList() {
        return categoryService.findCategorySelectList();
    }
}
